package com.hbnu.collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 需求：模拟欢乐斗地主发牌
 *
 * @author kittychen
 * @since 2025-10-15 8:26
 */
public class Poker {
    public static void main(String[] args) {
        // 1、创建一个集合，用于存放扑克牌
        List<String> pokers = new ArrayList<>(54);

        // 2、创建花色和数字（准备扑克）
        String[] colors = {"♠", "♥", "♣", "♦"};
        String[] numbers = {"2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};
        for (String color : colors) {
            for (String number : numbers) {
                pokers.add(color + number);
            }
        }
        pokers.add("大王");
        pokers.add("小王");

        // 3、洗牌（洗牌算法）
        Collections.shuffle(pokers);
        // System.out.println("洗牌：" + pokers);

        // 4、准备玩家和底牌
        List<String> player1 = new ArrayList<>(17);
        List<String> player2 = new ArrayList<>(17);
        List<String> player3 = new ArrayList<>(17);
        List<String> bottom = new ArrayList<>(3);

        // 5、发牌（遍历集合，给玩家和底牌发牌）
        for (int i = 0; i < pokers.size(); i++) {
            if (i < 3) {
                bottom.add(pokers.get(i));
            } else {
                if (i % 3 == 0) {
                    player1.add(pokers.get(i));
                } else if (i % 3 == 1) {
                    player2.add(pokers.get(i));
                } else {
                    player3.add(pokers.get(i));
                }
            }
        }

        // 6、查看牌型
        lookPokers("周润发", player1);
        lookPokers("刘德华", player2);
        lookPokers("周星驰", player3);
        lookPokers("底牌", bottom);
    }

    private static void lookPokers(String name, List<String> pokers) {
        System.out.println(name + "的牌：");
        for (String poker : pokers) {
            System.out.print(poker + "\t");
        }
        System.out.println();
    }
}
